package com.joey.protocol;

/**
 * Created by Joey on 2018/9/4.
 * 设置网络的一些默认值，比如默认key
 * 默认超时时间，
 * 默认错误处理等
 */

public class NetClientConfig {

    public static NetClientConfig I = new NetClientConfig();

    private ErrorListener listener;
    private JSONFormat jsonFormat = new JSONFormat();
    private boolean debug = false;

    private NetClientConfig() {
    }

    public static NetClientConfig I() {
        if (I == null) {
            synchronized (NetClientConfig.class) {
                if (I == null) {
                    I = new NetClientConfig();
                }
            }
        }
        return I;
    }

    protected ErrorListener getListener() {
        return listener;
    }

    public NetClientConfig setErrorListener(ErrorListener listener) {
        this.listener = listener;
        return this;
    }

    protected JSONFormat getJsonFormat() {
        return jsonFormat;
    }

    public NetClientConfig format(String statusKey, String resultKey, String messageKey) {
        this.jsonFormat.format(statusKey, resultKey, messageKey);
        return this;
    }

    public NetClientConfig initSuccessKey(String key) {
        this.jsonFormat.initSuccessKey(key);
        return this;
    }

    public NetClientConfig debug(boolean debug) {
        this.debug = debug;
        return this;
    }

    public boolean isDebug(){
        return debug;
    }
}
